﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UFIDA.U9.Cust.XH.PlugBE.Model;
using UFIDA.U9.Cust.XH.PlugBE.Tool;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;

namespace UFIDA.U9.Cust.XH.PlugBE
{
    class DepartmentInsertExtend : IEventSubscriber
    {
        /// <summary>
        /// 部门--进调度
        /// </summary>
        /// <param name="args"></param>
        public void Notify(params object[] args)
        {
            #region 从事件参数中取得当前业务实体													 

            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent))
                return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;
            if (key == null)
                return;
            UFIDA.U9.CBO.HR.Department.Department entity = key.GetEntity() as UFIDA.U9.CBO.HR.Department.Department;
            if (entity == null)
                return;

            #endregion
            DepModel model = new DepModel(entity);
            UFSoft.UBF.PL.Engine.ObjectState billState = entity.SysState;
            string acion = "add";
            if (billState == UFSoft.UBF.PL.Engine.ObjectState.Deleted)
            {
                acion = "delete";
            }
            DepOAModel depOA = new DepOAModel(acion, model.Code, model.Name, model.Name, model.OrgCode, model.ParentNode_Code, model);
            DepOAParam param = new DepOAParam();
            param.data.Add(depOA);
            string res = JsonConvert.SerializeObject(param);
            res = res.Replace("action", "@action");
            PubWebClass.SaveDept(res);





        }
    }
}
